Class Date

  • All Implemented Interfaces:
    java.lang.Comparable<Date>, ConsoleScanable

    public class Date
    extends java.lang.Object
    implements java.lang.Comparable<Date>, ConsoleScanable
    Version:
    234
    Author:
    TeM, JS
    Stage:
    ES04
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int d  
      private int m  
      private int y  
    • Constructor Summary

      Constructors 
      Constructor Description
      Date()  
      Date​(Date date)
      Copy constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addDay​(int n)  
      void addMonth​(int i)  
      void addYear​(int i)  
      int compareTo​(Date d)
      Compares this date to another date.
      java.lang.String dateString()  
      private java.lang.String dayName​(int w)  
      int getDay()  
      int getMonth()  
      int getYear()  
      boolean isLeap()  
      static int jul2lil​(int jul)
      converts Julian Day Number to Lilian Day Number
      int julianDayNumber()  
      static int julianDayNumber​(int y, int m, int d)
      returns the Julian Day Number for specified Date given as year, month and day (in Gregorian calendar) (for formulas see http://en.wikipedia.org/wiki/Julian_day)
      static int lil2jul​(int lil)
      converts Lilian Day Number to Julian Day Number
      int lilianDayNumber()  
      static int lilianDayNumber​(int y, int m, int d)
      returns the Lilian Date Number for the Date given as year, month, and day (in Grgorian calendar) (for details see http://en.wikipedia.org/wiki/Lilian_date)
      private java.lang.String monthName​(int month)  
      private java.lang.String numberEnding()  
      java.lang.String numericString()  
      boolean scan()
      Guides the user through a process that allows scanning/modifying an object with a text-based user interface.
      void setJulian​(int jul)
      sets the current Date to the Date given as Julian Day Number
      java.lang.String toString()  
      int weekday()
      Calculates the day of the week this date.
      0...SUN 6...SAT
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • y

        private int y
      • m

        private int m
      • d

        private int d
    • Constructor Detail

      • Date

        public Date​(Date date)
        Copy constructor
        Parameters:
        date - the date to copy
      • Date

        public Date()
    • Method Detail

      • getYear

        public int getYear()
        Returns:
        the year of this date
      • getDay

        public int getDay()
        Returns:
        the day of this date
      • getMonth

        public int getMonth()
        Returns:
        the month of this date
      • isLeap

        public boolean isLeap()
        Returns:
        true if this date is in a leap year, false otherwise
      • weekday

        public int weekday()
        Calculates the day of the week this date.
        0...SUN 6...SAT
        Returns:
        the weekday of this date
      • dateString

        public java.lang.String dateString()
        Returns:
        a formatted String representing this date
      • numberEnding

        private java.lang.String numberEnding()
        Returns:
        the number ending of a the day of this date
      • monthName

        private java.lang.String monthName​(int month)
        Parameters:
        month - the month for which the English name shall be calculated
        Returns:
        the English name of a month
      • dayName

        private java.lang.String dayName​(int w)
        Parameters:
        w - the number of the day (as explained in weekday())
        Returns:
        the English name of a day of the week
      • addDay

        public void addDay​(int n)
        Parameters:
        n - the number of days to add to this date
      • addMonth

        public void addMonth​(int i)
        Parameters:
        i - the number of months to add to this date
      • addYear

        public void addYear​(int i)
        Parameters:
        i - the number of year to add to this date
      • julianDayNumber

        public static int julianDayNumber​(int y,
                                          int m,
                                          int d)
        returns the Julian Day Number for specified Date given as year, month and day (in Gregorian calendar) (for formulas see http://en.wikipedia.org/wiki/Julian_day)
        Parameters:
        y - year
        m - month
        d - day
        Returns:
        the Julian Day Number
      • julianDayNumber

        public int julianDayNumber()
        Returns:
        the Julian Day Number for this Date (for formulas see http://en.wikipedia.org/wiki/Julian_day)
      • lil2jul

        public static int lil2jul​(int lil)
        converts Lilian Day Number to Julian Day Number
        Parameters:
        lil - Lilian day number
        Returns:
        the Julian Day Number of the day specified by its Lilian Day Number
      • jul2lil

        public static int jul2lil​(int jul)
        converts Julian Day Number to Lilian Day Number
        Parameters:
        jul - Julian day number
        Returns:
        the Lilian Day Number of the day specified by its Julian Day Number
      • lilianDayNumber

        public int lilianDayNumber()
        Returns:
        returns the Lilian Date Number for this Date for details see http://en.wikipedia.org/wiki/Lilian_date
      • lilianDayNumber

        public static int lilianDayNumber​(int y,
                                          int m,
                                          int d)
        returns the Lilian Date Number for the Date given as year, month, and day (in Grgorian calendar) (for details see http://en.wikipedia.org/wiki/Lilian_date)
        Parameters:
        y - year
        m - month
        d - day
        Returns:
        the Lilian Day Number of the specified date
      • setJulian

        public void setJulian​(int jul)
        sets the current Date to the Date given as Julian Day Number
        Parameters:
        jul - Julian Day Number
      • numericString

        public java.lang.String numericString()
        Returns:
        a formatted String representing this date
      • compareTo

        public int compareTo​(Date d)
        Compares this date to another date.
        Specified by:
        compareTo in interface java.lang.Comparable<Date>
        Parameters:
        d - the date to compare this date to
        Returns:
        a measure of the distance between this date and another date
      • scan

        public boolean scan()
        Description copied from interface: ConsoleScanable
        Guides the user through a process that allows scanning/modifying an object with a text-based user interface. Implementing classes may choose to provide a cancel mechanism and/or a keep-old-value mechanism. The user interaction is completely left to implementing classes and must be documented there.

        Documentation should include:

        • which fields and in which order they can be modified
        • if and how cancellation and keeping old values works
        • how illegal inputs are dealt with (message, repeated input of single field or all fields,...)
        Specified by:
        scan in interface ConsoleScanable
        Returns:
        true if this date was modified during the operation, false otherwise
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object